package top.eggcode.common.model;

import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * 表格页面
 *
 * @author JiaQi Ding
 */
@ToString(callSuper = true)
@Accessors(chain = true)
@Data
public class ListPage<T> {

    /**
     * 页长度
     */
    private long size;

    /**
     * 页位置
     */
    private long number;

    /**
     * 总记录数
     */
    private long total;

    private List<T> list;

    public ListPage() {
    }

    public ListPage(long size, long number, long total, List<T> content) {
        this.size = size;
        this.number = number;
        this.total = total;
        this.list = content;
    }

    public ListPage<T> convert(org.springframework.data.domain.Page page) {
        this.setNumber(page.getNumber());
        this.setSize(page.getSize());
        this.setTotal(page.getTotalElements());
        return this;
    }
}
